#!/usr/bin/python
# Filename: agent.py

import os
import sys
import time
import platform
import psutil
import socket
import datetime
import urllib2
import urllib
import threading
from Daemon import *
from Agent import *

class MyDaemon(Daemon):
   def run(self):
      fd = open("/home/quentin/logBlissAgent.txt","w+")
      fd.close()
      agent = Agent()
      while True:
         agent.updateInfos()
         self.saveLog(agent.getInfos())
         time.sleep(60)
   
   def saveLog(self, text):
      """
      """
      fd = open("/home/quentin/logBlissAgent.txt","a+")
      fd.write("%s:%s\n" %(datetime.datetime.now(),text))
      fd.close()	
if __name__ == "__main__":
        daemon = MyDaemon('/tmp/daemonBlissAgent.pid')
        if len(sys.argv) == 2:
                if 'start' == sys.argv[1]:
                        daemon.start()
                elif 'stop' == sys.argv[1]:
                        daemon.stop()
                elif 'restart' == sys.argv[1]:
                        daemon.restart()
                else:
                        print "Unknown command"
                        sys.exit(2)
                sys.exit(0)
        else:
                print "usage: %s start|stop|restart" % sys.argv[0]
                sys.exit(2)
		
def update():
   system.updateInfos()
   system.sendRequest("http://127.0.0.1:82/Bliss/json/agent/report",system.getInfos())


